package clientGUI;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import librarianPanels.BorrowBookPanel;
import librarianPanels.CreateReaderCardPanel;
import librarianPanels.InventoryManagementPanel;
import librarianPanels.MessagesPanel;
import librarianPanels.ReturnABookPanel;
import librarianPanels.ViewBookOrdersPanel;
import librarianPanels.WatchReaderCardPanel;

/**
 * @author Shay
 * Creating Librarian GUI
 */
public class LibrarianGUI extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Create the panel of the librarian GUI
	 */
	private final static LibrarianGUI lGUI=null;
	public JLabel labelbooks;
	public JButton canceledButton;
	private JButton btnNewReaderCard;
	private JButton btnBorrowABook;
	private JButton btnInventoryManagement;
	private JButton btnReturnABook;
	protected JButton btnWatchReaderCard;
	private JButton btnSearch;
	private JButton btnLogout;
	protected JButton btnLibraryMessages;
	public static LibrarianGUI getInstance()
	{
		if(lGUI==null)
			return new LibrarianGUI();
		return lGUI;
	}
	
	protected LibrarianGUI() {
		canceledButton=new JButton();
		setBorder(new LineBorder(new Color(0, 0, 0), 3, true));
		setLayout(null);
		setPreferredSize(new Dimension(219, 547));
		btnNewReaderCard = new JButton("Create New Reader Card");
		btnNewReaderCard.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				CreateReaderCardPanel p=new CreateReaderCardPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnNewReaderCard;
				canceledButton.setEnabled(false);
			}
		});
		btnNewReaderCard.setBounds(10, 11, 199, 41);
		add(btnNewReaderCard);
		
		btnBorrowABook = new JButton("Borrow A Book");
		btnBorrowABook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				BorrowBookPanel p=new BorrowBookPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnBorrowABook;
				canceledButton.setEnabled(false);
			}
		});
		
		btnBorrowABook.setBounds(10, 63, 199, 41);
		add(btnBorrowABook);
		
		btnInventoryManagement = new JButton("Inventory Management");
		btnInventoryManagement.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				InventoryManagementPanel p=new InventoryManagementPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnInventoryManagement;
				canceledButton.setEnabled(false);
			}
		});
		btnInventoryManagement.setBounds(10, 167, 199, 41);
		add(btnInventoryManagement);
		
		btnReturnABook = new JButton("Return A Book");
		btnReturnABook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				ReturnABookPanel p=new ReturnABookPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnReturnABook;
				canceledButton.setEnabled(false);
			}
		});
		btnReturnABook.setBounds(10, 219, 199, 41);
		add(btnReturnABook);
		
		btnWatchReaderCard = new JButton("Watch Reader Card");
		btnWatchReaderCard.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				WatchReaderCardPanel p=new WatchReaderCardPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnWatchReaderCard;
				canceledButton.setEnabled(false);
			}
		});
		btnWatchReaderCard.setBounds(10, 271, 199, 41);
		add(btnWatchReaderCard);
		
		btnSearch = new JButton("Search");
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				ViewBookOrdersPanel p=new ViewBookOrdersPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnSearch;
				canceledButton.setEnabled(false);
			}
		});
		btnSearch.setBounds(10, 117, 199, 41);
		add(btnSearch);
		
		btnLogout = new JButton("Logout");
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String x[]=new String[1];
				x[0]="Logoff";
				MainGUI.OBLClient.handleMessageFromClient(x);
			}
		});
		btnLogout.setBounds(10, 480, 199, 41);
		add(btnLogout);
		
		
		btnLibraryMessages = new JButton("Librarian Messages");
		btnLibraryMessages.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MessagesPanel p=new MessagesPanel();
				MainGUI.middlePanelChange(p);
				canceledButton.setEnabled(true);
				canceledButton=btnLibraryMessages;
				canceledButton.setEnabled(false);
			}
		});
		btnLibraryMessages.setBounds(10, 426, 199, 41);
		add(btnLibraryMessages);
		labelbooks = new JLabel("");
		labelbooks.setIcon(new ImageIcon("images/book3.jpg"));
		labelbooks.setBounds(3, 3, 215, 540);
		add(labelbooks);
	}
}
